package com.heu.blood.statistic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heu.blood.bloodtest.service.BloodTestService;
import com.heu.blood.match.service.BloodInformationService;
import com.heu.blood.statistic.dao.BloodDataAnalysisDao;
import com.heu.blood.statistic.entity.*;
import com.heu.blood.statistic.service.BloodDataAnalysisService;
import com.heu.blood.storge.service.BloodInStorgeService;
import com.heu.blood.transfusion.service.TransfusionApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service("bloodDataAnalysisServiceImpl")
public class BloodDataAnalysisServiceImpl extends ServiceImpl<BloodDataAnalysisDao, BloodDataAnalysis> implements BloodDataAnalysisService {

    @Autowired
    private BloodDataAnalysisDao bloodDataAnalysisDao;

    @Autowired
    private TransfusionApplicationService transfusionApplicationService;

    @Autowired
    private BloodTestService bloodTestService;

    @Autowired
    private BloodInStorgeService bloodInStorgeService;

    @Autowired
    private BloodInformationService bloodInformationService;

    /**
     * 获取首页分析数据
     * @return
     */
    @Override
    public BloodDataAnalysis getDataAnalysis() {
        // 获取今日用血申请数
        Integer applyNum = transfusionApplicationService.getApplyNum();
        // 获取当天检验样本数量
        Integer testNum = bloodTestService.getTestNum();
        // 获取当天血液入库数量
        Integer inStoreNum = bloodInStorgeService.inStorgeNum();
        // 七日用血科室用血数量统计
        List<DepartmentUseNum> departmentUseNums = transfusionApplicationService.getSevenDaysDepartmentUseNum();
        // 获取七日用血申请单数
        List<ApplyData> sevenDaysApplyNum = transfusionApplicationService.getSevenDaysApply();
        // 获取库存血液按照类型统计
        List<BloodStoreCountType> bloodStoreCountTypes = bloodInformationService.selectBloodTypeCount();
        // 获取库存血型数量统计
        List<BloodStoreCountABO> bloodStoreCountABOS = bloodInformationService.selectAboTypeCount();
        // 封装最后结果
        BloodDataAnalysis bloodDataAnalysis = new BloodDataAnalysis(applyNum, testNum, inStoreNum, departmentUseNums,
                sevenDaysApplyNum, bloodStoreCountTypes, bloodStoreCountABOS);
        // 返回结果
        return bloodDataAnalysis;
    }
}
